package org.icress.fusion.ws

class SendScanJobService {

    static transactional = false

    def calloutService

    def scan() {
        
        def outBoundInstance = OutBound.withCriteria(uniqueResult:true){
            projections{
                //取出站消息ID
                property("id")
            }
            /*
            or{
                //异步方式，未获取到队列ID
                and{
                    isNull("jobId")
                    eq("asynchronous", true)
                }
                //同步方式，状态为空
                and{
                    isNull("status")
                    eq("asynchronous", false)
                }
            }
            //未达到限制次数
            or{
                isNull("retrySendError")
                ltProperty("retrySendError", "retrySendErrorLimit")
            }
            */
            eq('stage', '待发送')
            order("priority", "asc")
            order("retrySendError", "asc")
            order("id", "asc")
            maxResults(1)
        }
        //OutBound.withSession{ status ->
            if(outBoundInstance){
                calloutService.fire(outBoundInstance.toLong())
            }
        //}
    }
}
